#!/usr/bin/env bash
# Load functions and variables
. /usr/bin/common
arg=$(cat /usr/bin/.args)
args=$(echo $arg)
jbt=$(cat /usr/bin/.jbtype)
jbtype=$(echo $jbt)

export NEWT_COLORS='root=,black
border=white,black
title=white,black
roottext=red,black
window=red,black
textbox=white,black
button=black,green
compactbutton=white,black
listbox=white,black
actlistbox=black,white
actsellistbox=black,green
checkbox=green,black
actcheckbox=black,green
'

whiptail_height="$(($(tput lines) - 6))"
whiptail_width="$(($(tput cols) - 20))"

if [ "$jbtype" = "Rootless" ]; then
while true; do
  CHOICE="$(whiptail --nocancel --title "palera1n | use arrow keys" --menu \
    "
  Jailbreak Type: $jbtype
  Arguments: $args" $whiptail_height $whiptail_width 8 \
    '1' 'Start' \
    '2' 'Options' \
    '3' 'Switch' \
    '4' 'Exit' 3>&1 1>&2 2>&3)"
  case "$CHOICE" in
    1)
      clear
      echo ''
      echo "# == INFORMATION =="
      echo "# ${YELLOW}- If you encounter lockdownd errors make sure to${NORMAL}"
      echo "# ${YELLOW}unlock your device and replug.${NORMAL}"
      echo "# ${YELLOW}- arm64e is not supported!${NORMAL}"
      echo "# ${YELLOW}- You may encounter issues with AMD cpus.${NORMAL}"
      echo "# ===== DEBUG ====="
      echo "# Chosen Jailbreak Type: ${BLUE}$jbtype${NORMAL}"
      echo "# Chosen Flags: ${BLUE}$args${NORMAL}"
      echo ''
      /usr/bin/palera1n $args
      sleep 2
      echo ''
      echo "# ===== DEBUG ====="
      echo "# Chosen Jailbreak Type: ${BLUE}$jbtype${NORMAL}"
      echo "# Chosen Flags: ${BLUE}$args${NORMAL}"
      echo ''
      enter_to_quit
      /usr/bin/palera1n_menu
      ;;
    2)
      clear
      /usr/bin/palera1n_options
      ;;
    3)
      clear
       /usr/bin/palera1n_switch
       ;;
     4)
      clear
      /usr/bin/palen1x_menu
      ;;
  esac
done
elif [ "$jbtype" = "Rootful" ]; then
while true; do
  CHOICE="$(whiptail --nocancel --title "palera1n | use arrow keys" --menu \
    "
  Jailbreak Type: $jbtype
  Arguments: -f $args" $whiptail_height $whiptail_width 8 \
    '1' 'Start' \
    '2' 'Options' \
    '3' 'Switch' \
    '4' 'Exit' 3>&1 1>&2 2>&3)"
  case "$CHOICE" in
    1)
      clear
      echo ''
      echo "# == INFORMATION =="
      echo "# ${YELLOW}- Rootful has been depreciated, and does not support iPadOS 17.${NORMAL}"
      echo "# ${YELLOW}- A future version of palen1x will remove fakefs/bindfs creation support.${NORMAL}"
      echo "# ${YELLOW}- If you encounter lockdownd errors make sure to${NORMAL}"
      echo "# ${YELLOW}unlock your device and replug.${NORMAL}"
      echo "# ${YELLOW}- arm64e is not supported!${NORMAL}"
      echo "# == DEBUG =="
      echo "# Chosen Jailbreak Type: ${BLUE}$jbtype${NORMAL}"
      echo "# Chosen Flags: -f ${BLUE}$args${NORMAL}"
      /usr/bin/palera1n -f $args
      sleep 2
      echo ''
      echo "# == DEBUG =="
      echo "# Chosen Jailbreak Type: ${BLUE}$jbtype${NORMAL}"
      echo "# Chosen Flags: -f ${BLUE}$args${NORMAL}"
      echo ''
      enter_to_quit
      /usr/bin/palera1n_menu
      ;;
    2)
      clear
      /usr/bin/palera1n_options
      ;;
    3)
      clear
       /usr/bin/palera1n_switch
       ;;
     4)
      clear
      /usr/bin/palen1x_menu
      ;;
  esac
done
fi
